/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/impl/{{entities@SQL}}ServiceImpl.java.hbs
 */
// @SkipOverwrite
package cn.ibizlab.core.ad.service.impl;

import cn.ibizlab.core.ad.domain.SysActiveDirectory;
import cn.ibizlab.core.ad.domain.SysOrganization;
import cn.ibizlab.core.ad.filter.SysActiveDirectorySearchContext;
import cn.ibizlab.core.ad.service.SysOrganizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 实体[AD] 服务对象接口实现
 *
 * @author generator
 */
@Slf4j
@Service("SysActiveDirectoryService")
public class SysActiveDirectoryServiceImpl extends AbstractSysActiveDirectoryService {

    @Autowired
    private SysOrganizationService sysOrganizationService;

    @Override
    public List<SysActiveDirectory> items(SysActiveDirectory dto) {
        SysActiveDirectorySearchContext context = new SysActiveDirectorySearchContext();
        if(!ObjectUtils.isEmpty(dto.getDepartmentId()))
            context.setDepartmentIdEQ(dto.getDepartmentId());
        if(!ObjectUtils.isEmpty(dto.getParentId()))
            context.setParentIdEQ(dto.getParentId());
        if(!ObjectUtils.isEmpty(dto.getFilter()))
            context.setFilterLIKE(dto.getFilter());
        String orgId = dto.getId();
        if(!ObjectUtils.isEmpty(orgId)) {
            orgId = sysOrganizationService.findOrganizationId(new SysOrganization().setId(orgId).setDc(dto.getDc()));
            if(!ObjectUtils.isEmpty(orgId)) {
                context.setOrganizationIdEQ(orgId);
                return this.listDefault(context);
            }
        }
        return this.listMyOrg(context);
    }
}